<?php


class VodStream extends CActiveRecord
{
    	const STREAM_VIDEO   = 1;
        const STREAM_TRAILER = 2;
    
        const SERVER_STATUS_ACTIVE      = 1;
        const SERVER_STATUS_INACTIVE    = 0;
        const SERVER_STATUS_TEST        = 2;
        
        const STREAM_PROTOCOL_HTTP = 0; 
        const STREAM_PROTOCOL_RTSP = 1; 
        const STREAM_PROTOCOL_HLS  = 2; 
        const STREAM_PROTOCOL_RTMP = 3;
        const STREAM_PROTOCOL_MMS = 4;
        const STREAM_PROTOCOL_ALL  = -1;
        
	
	public static function model($Vgmajjibziuy=__CLASS__)
	{
		return parent::model($Vgmajjibziuy);
	}

	
	public function tableName()
	{
		return 'vod_stream';
	}

	
	public function rules()
	{
		
		
		return array(
			array('stream_url', 'required'),
			array('vod_asset_id, vod_episode_id, resolution_w, resolution_h, bitrate, stream_type, create_user_id, status, server_id, protocol', 'numerical', 'integerOnly'=>true),
			array('stream_url', 'length', 'max'=>500),
			array('create_date', 'safe'),
			
			
			array('id, vod_asset_id, vod_episode_id, stream_url, resolution_w, resolution_h, bitrate, stream_type, create_date, create_user_id, status, server_id, protocol', 'safe', 'on'=>'search'),
		);
	}

	
	public function relations()
	{
		
		
		return array(
			'createUser' => array(self::BELONGS_TO, 'BackendUser', 'create_user_id'),
			'vodAsset' => array(self::BELONGS_TO, 'VodAsset', 'vod_asset_id'),
		);
	}

	
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'vod_asset_id' => 'Vod Asset',
			'vod_episode_id' => 'Vod Episode',
			'stream_url' => 'Stream Url',
			'resolution_w' => 'Resolution W',
			'resolution_h' => 'Resolution H',
			'bitrate' => 'Bitrate',
			'stream_type' => 'Stream Type',
			'create_date' => 'Create Date',
			'create_user_id' => 'Create User',
			'status' => 'Status',
			'server_id' => 'Server',
			'protocol' => 'Protocol',
		);
	}

	
	public function search()
	{
		
		

		$V0v5vsnfxezw=new CDbCriteria;

		$V0v5vsnfxezw->compare('id',$this->id);
		$V0v5vsnfxezw->compare('vod_asset_id',$this->vod_asset_id);
		$V0v5vsnfxezw->compare('vod_episode_id',$this->vod_episode_id);
		$V0v5vsnfxezw->compare('stream_url',$this->stream_url,true);
		$V0v5vsnfxezw->compare('resolution_w',$this->resolution_w);
		$V0v5vsnfxezw->compare('resolution_h',$this->resolution_h);
		$V0v5vsnfxezw->compare('bitrate',$this->bitrate);
		$V0v5vsnfxezw->compare('stream_type',$this->stream_type);
		$V0v5vsnfxezw->compare('create_date',$this->create_date,true);
		$V0v5vsnfxezw->compare('create_user_id',$this->create_user_id);
		$V0v5vsnfxezw->compare('status',$this->status);
		$V0v5vsnfxezw->compare('server_id',$this->server_id);
		$V0v5vsnfxezw->compare('protocol',$this->protocol);

		return new CActiveDataProvider($this, array(
			'criteria'=>$V0v5vsnfxezw,
		));
	}
        
        static public function getProtocol($Vif53wwzmbl1) {
            if(strpos($Vif53wwzmbl1,'http') === 0) {
                $Vf0wtt1q0lik = VodStream::STREAM_PROTOCOL_HLS;
            }
            else if(strpos($Vif53wwzmbl1,'rtsp') === 0) {
                $Vf0wtt1q0lik = VodStream::STREAM_PROTOCOL_RTSP;
            }
            else if(strpos($Vif53wwzmbl1,'rtmp') === 0) {
                $Vf0wtt1q0lik = VodStream::STREAM_PROTOCOL_RTMP;
            }
            else if(strpos($Vif53wwzmbl1,'youtube') > 0) {
                $Vf0wtt1q0lik = VodStream::STREAM_PROTOCOL_YOUTUBE;
            }
            return $Vf0wtt1q0lik;
        }
}